package com.matrixxun.pulltozoomlistsimple;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.matrixxun.pulltozoomlistsimple.PullToZoomListView.onPullRefreshListener;

public class MainActivity extends Activity {
	PullToZoomListView listView;
	private String[] adapterData;
	ProgressBar progressBar1;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		listView = (PullToZoomListView) findViewById(R.id.listview);
		adapterData = new String[] { "Activity", "Activity", "Activity",
				"Activity", "Activity", "Activity", "Activity", "Activity",
				"Activity", "Activity", "Activity", "Activity", "Service",
				"Activity", "Activity", "Activity", "Activity", "Service",
				"Activity", "Activity", "Activity", "Activity", "Service",
				"Activity", "Activity", "Activity", "Activity", "Service",
				"Content Provider", "Intent", "BroadcastReceiver", "ADT",
				"Sqlite3", "HttpClient", "DDMS", "Android Studio", "Fragment",
				"Loader" };

		listView.setAdapter(new ArrayAdapter<String>(MainActivity.this,
				android.R.layout.simple_list_item_1, adapterData));
		listView.getHeaderView().setImageResource(R.drawable.bg);
		listView.getHeaderView().setScaleType(ImageView.ScaleType.CENTER_CROP);
//		listView.setOnItemLongClickListener(new OnItemLongClickListener() {
//
//			@Override
//			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
//					int arg2, long arg3) {
//				// TODO Auto-generated method stub
//				return true;
//			}
//		});
		progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
		progressBar1.setVisibility(View.GONE);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Toast.makeText(getBaseContext(), "" + arg2, 0).show();
			}
		});
		listView.setOnPullRefreshListener(new onPullRefreshListener() {
			
			@Override
			public void onHead() {
				Toast.makeText(getBaseContext(), "onHead", 0).show();
				complemt();
			}

			private void complemt() {
				progressBar1.setVisibility(View.VISIBLE);
				new Handler().postDelayed(new Runnable() {
					
					@Override
					public void run() {
						listView.setLoadComplemt();
						progressBar1.setVisibility(View.GONE);
					}
				}, 2000);
			}
			
			@Override
			public void onFoot() {
				Toast.makeText(getBaseContext(), "onFoot", 0).show();
				complemt();
			}
		});
	}
}
